package com.sun.hunk.hibernate.domain.impl;

import com.sun.hunk.hibernate.domain.Charge;
import com.sun.hunk.hibernate.domain.GenericCode;
import com.sun.hunk.hibernate.domain.Invoice;
import com.sun.hunk.util.UniqueID;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 *
 * @author sunil
 */
@Entity
@Table(name = "charge")
public class ChargeImpl implements Charge {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "id")
    private Long id;
    @Column(name = "marks_no")
    private String marksNo;
    @Column(name = "package_type")
    private String packageType;
    @Column(name = "package_size")
    private String size;
    @Column(name = "package_weight")
    private String weight;
    @Column(name = "packages")
    private Integer packages;
    @Column(name = "good_description")
    private String goodDescription;
    @Column(name = "hs_code")
    private String hsCode;
    @Column(name = "quantity")
    private Integer quantity;
    @Column(name = "amount")
    private Double amount;
    @Column(name = "markup")
    private Double markup;
    @Column(name = "adjustment")
    private Double adjustment;
    @Column(name = "comment")
    private String comment;
    @JoinColumn(name = "invoice_id", referencedColumnName = "id")
    @ManyToOne(targetEntity=InvoiceImpl.class)
    private Invoice invoice;
    @JoinColumn(name = "currency_id", referencedColumnName = "id")
    @ManyToOne(targetEntity=GenericCodeImpl.class)
    private GenericCode currency;

    public ChargeImpl() {
        id = UniqueID.getLong();
        quantity = 1;
    }

    public ChargeImpl(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getMarksNo() {
        return marksNo;
    }

    public void setMarksNo(String marksNo) {
        this.marksNo = marksNo;
    }

    public Integer getPackages() {
        return packages;
    }

    public void setPackages(Integer packages) {
        this.packages = packages;
    }

    public String getGoodDescription() {
        return goodDescription;
    }

    public void setGoodDescription(String goodDescription) {
        this.goodDescription = goodDescription;
    }

    public Integer getQuantity() {
        return quantity;
    }

    public void setQuantity(Integer quantity) {
        this.quantity = quantity;
    }

    public Double getAmount() {
        return amount;
    }

    public String getPackageType() {
        return packageType;
    }

    public void setPackageType(String packageType) {
        this.packageType = packageType;
    }

    public String getSize() {
        return size;
    }

    public void setSize(String size) {
        this.size = size;
    }

    public String getWeight() {
        return weight;
    }

    public void setWeight(String weight) {
        this.weight = weight;
    }


    public Double getTotalAmount() {
        double total = 0.0; 
        if(amount != null){
            total += amount;
        }
        if(quantity != null){
            total *= quantity;
        }
        return total;
    }

    public void setAmount(Double amount) {
        this.amount = amount;
    }

    public Double getMarkup() {
        return markup;
    }

    public void setMarkup(Double markup) {
        this.markup = markup;
    }

    public Double getAdjustment() {
        return adjustment;
    }

    public void setAdjustment(Double adjustment) {
        this.adjustment = adjustment;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public Invoice getInvoice() {
        return invoice;
    }

    public void setInvoice(Invoice invoice) {
        this.invoice = invoice;
    }

    public GenericCode getCurrency() {
        return currency;
    }

    public void setCurrency(GenericCode currency) {
        this.currency = currency;
    }

    public String getHsCode() {
        return hsCode;
    }

    public void setHsCode(String hsCode) {
        this.hsCode = hsCode;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ChargeImpl)) {
            return false;
        }
        ChargeImpl other = (ChargeImpl) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.sun.hunk.hibernate.domain.impl.Charge[id=" + id + "]";
    }

}
